package test;

import java.util.Scanner;

import questions.Questions;
/**
 * 
 * @author Evgeny
 *
 */
public class UserInterface {

	private final static String SPLIT = "[,]";

	public UserInterface() {
		System.out.println("Тестирование");
	}

	public String getUsername() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("Введите ваше имя:");
		return scanner.nextLine();
	}

	public String getUserPassword() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("Введите пароль:");
		return scanner.nextLine();
	}

	public String loadMainMenu(boolean isAdmin) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("1.Посмотреть статистику");
		System.out.println("2.Начать тест");
		System.out.println("3.Выйти");
		if(isAdmin)
			System.out.println("4.Посмотреть статистику всех пользователей");
		return scanner.nextLine();
	}

	public void printStatistics(String score) {
		System.out.println(score);

	}

	public int test(Questions questions, int priceQuestion) {
		Scanner scanner = new Scanner(System.in);
		int score = 0;
		for (int i = 0; i < questions.length(); i++) {
			System.out.println(questions.getQuestion(i));
			String answers = "";
			if ((answers = questions.getAnswers(i)) != null) {
				String[] strings = answers.split(SPLIT);
				for (String str : strings)
					System.out.println(str);
			}
			String str=scanner.nextLine();
			if(str.equalsIgnoreCase("прервать")) break;
			if (questions.isCorrectAnswer(i,str))
				score += priceQuestion;
		}
		System.out.printf("Вы набрали: %d из %d баллов\n", score, priceQuestion
				* questions.length());
		return score;
	}

	public void printMessage(String message) {
		System.out.println(message);

	}
}
